﻿using System;
using System.Diagnostics;
using System.IO;

namespace Shoping.Monitor.Helper
{
    public class UrlToImage
    {
        public static string Invoke(string url)
        {
            return "";
        }


        public static bool Invoke(System.Windows.Forms.Control control , string url, string path)
        {
            try
            {
                if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path))
                    return false;
                        string str = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PageToPDF.exe ");
                        if (!System.IO.File.Exists(str))
                            return false;
                control.Invoke(new Action(() =>
                    {
                        try
                        {
                        var p = new Process
                            {
                                StartInfo =
                                    {
                                        FileName = str,
                                        Arguments = " \"" + url + "\" " + path,
                                        UseShellExecute = false,
                                        RedirectStandardInput = true,
                                        RedirectStandardOutput = true,
                                        RedirectStandardError = true,
                                        CreateNoWindow = true
                                    }
                            };
                        p.Start();

                        }
                        catch (Exception ex)
                        {
                             
                        }
                    }));
               
                while (true)
                {

                    System.Threading.Thread.Sleep(500);
                    if (System.IO.File.Exists(path))
                    {
                        return true;
                    }
                }
                return true;
            }
            catch (Exception ex)
            {

            }
            return false;


        }
    }
}